///**
// * Copyright 2018 人人开源 http://www.report.io
// * <p>
// * Licensed under the Apache License, Version 2.0 (the "License"); you may not
// * use this file except in compliance with the License. You may obtain a copy of
// * the License at
// * <p>
// * http://www.apache.org/licenses/LICENSE-2.0
// * <p>
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// * License for the specific language governing permissions and limitations under
// * the License.
// */
//
//package com.lyc.demo.common.config;
//
//import io.report.modules.sys.shiro.RedisShiroSessionDAO;
//import io.report.modules.sys.shiro.UserRealm;
//import org.apache.shiro.mgt.SecurityManager;
//import org.apache.shiro.session.mgt.SessionManager;
//import org.apache.shiro.spring.LifecycleBeanPostProcessor;
//import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
//import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
//import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.server.session.DefaultWebSessionManager;
//
//import java.util.LinkedHashMap;
//import java.util.Map;
//
///**
// * Shiro的配置文件
// *
// * @author Mark sunlightcs@gmail.com
// * @since 3.0.0 2017-09-27
// */
//@Configuration
//public class ShiroConfig {
//
//    @Bean("sessionManager")
//    public SessionManager sessionManager(RedisShiroSessionDAO redisShiroSessionDAO,
//                                         @Value("${report.redis.open}") boolean redisOpen,
//                                         @Value("${report.shiro.redis}") boolean shiroRedis,
//                                         @Value("${report.globalSessionTimeout:3600}") long globalSessionTimeout){
//        DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
//        //设置session过期时间为1小时(单位：毫秒)，默认为30分钟
//        sessionManager.setGlobalSessionTimeout(globalSessionTimeout* 1000);
//        sessionManager.setSessionValidationSchedulerEnabled(true);
//        sessionManager.setSessionIdUrlRewritingEnabled(false);
//
//        //如果开启redis缓存且report.shiro.redis=true，则shiro session存到redis里
//        if(redisOpen && shiroRedis){
//            sessionManager.setSessionDAO(redisShiroSessionDAO);
//        }
//        return sessionManager;
//    }
//
//    @Bean("securityManager")
//    public SecurityManager securityManager(UserRealm userRealm, SessionManager sessionManager) {
//        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
//        securityManager.setRealm(userRealm);
//        securityManager.setSessionManager(sessionManager);
//
//        return securityManager;
//    }
//
//
//    @Bean("shiroFilter")
//    public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager,
//    		@Value("${report.auth.state}") boolean authState) {
//        ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
//        shiroFilter.setSecurityManager(securityManager);
//        shiroFilter.setLoginUrl("/login.html");
//        shiroFilter.setUnauthorizedUrl("/");
//
//        Map<String, String> filterMap = new LinkedHashMap<>();
//        filterMap.put("/swagger/**", "anon");
//        filterMap.put("/v2/api-docs", "anon");
//        filterMap.put("/swagger-ui.html", "anon");
//        filterMap.put("/webjars/**", "anon");
//        filterMap.put("/swagger-resources/**", "anon");
//
//        filterMap.put("/statics/**", "anon");
//        filterMap.put("/login.html", "anon");
//        filterMap.put("/developing.html", "anon");
//        filterMap.put("/sys/login", "anon");
//        filterMap.put("/favicon.ico", "anon");
//        filterMap.put("/captcha.jpg", "anon");
//        filterMap.put("/ex/**", "anon");
//        if(authState) {
//        	filterMap.put("/rdppub/**", "anon");
//        	filterMap.put("/rdppage/**", "anon");
//        	filterMap.put("/mapfiles/**", "anon");
//        	filterMap.put("/bddpfiles/**", "anon");
//        	filterMap.put("/bddpshow/**", "anon");
//        	filterMap.put("/bddpConfig/**", "anon");
//        	filterMap.put("/material/**", "anon");
//        	filterMap.put("/bddpDiyTag/**", "anon");
//        	filterMap.put("/bddpdemo/**", "anon");
//        	// filterMap.put("/rdp/**", "anon");
//        	//filterMap.put("/bddp/**", "anon");
//        	filterMap.put("/modules/bddp/**", "anon");
//        	filterMap.put("/modules/rdp/**", "anon");
//        }
//        filterMap.put("/**", "authc");
//        shiroFilter.setFilterChainDefinitionMap(filterMap);
//
//        return shiroFilter;
//    }
//
//    @Bean("lifecycleBeanPostProcessor")
//    public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
//        return new LifecycleBeanPostProcessor();
//    }
//
//    @Bean
//    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
//        DefaultAdvisorAutoProxyCreator proxyCreator = new DefaultAdvisorAutoProxyCreator();
//        proxyCreator.setProxyTargetClass(true);
//        return proxyCreator;
//    }
//
//    @Bean
//    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
//        AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
//        advisor.setSecurityManager(securityManager);
//        return advisor;
//    }
//}
